<?php

namespace Account\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class AccessController extends AbstractActionController
{
    protected $accessTable;
    protected $access;
    protected $account_id;

    public function __construct($account_id = null)
    {
        $this->account_id = $account_id;
    }

    public function getAccessTable()
    {
        if (!$this->accessTable) {
            $sm = $this->getServiceLocator();
            $this->accessTable = $sm->get('Access\Model\AccessTable');
        }
        return $this->accessTable;
    }

    /**
     * 初始化页面渲染
     * @return array|ViewModel
     */
    public function indexAction()
    {
        $this->account_id = $this->params()->fromRoute('id', null);
        $this->access = $this->getAccessTable()->getAccessByAccountId($this->account_id);
        $view = new ViewModel(array(
            'account_id' => $this->account_id,
            'access' => $this->access
        ));
        return $view;
    }
}